package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 批注类型枚举
 *
 * <p>管理网上批阅系统中的各种批注类型。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum AnnotationType implements BaseEnum {

    /** 文本批注 */
    TEXT("TEXT", "文本批注"),

    /** 绘制批注 */
    DRAWING("DRAWING", "绘制批注"),

    /** 标记批注 */
    MARKUP("MARKUP", "标记批注"),

    /** 音频批注 */
    AUDIO("AUDIO", "音频批注"),

    /** 视频批注 */
    VIDEO("VIDEO", "视频批注"),

    /** 订正批注 */
    CORRECTION("CORRECTION", "订正批注"),

    /** 评价批注 */
    EVALUATION("EVALUATION", "评价批注"),

    /** 模板批注 */
    TEMPLATE("TEMPLATE", "模板批注"),

    /** 评论批注 */
    COMMENT("COMMENT", "评论批注"),

    /** 疑问批注 */
    QUESTION("QUESTION", "疑问批注"),

    /** 回答批注 */
    ANSWER("ANSWER", "回答批注"),

    /** 系统批注 */
    SYSTEM("SYSTEM", "系统批注"),

    /** 自动评分批注 */
    AUTO_GRADE("AUTO_GRADE", "自动评分批注"),

    /** 其他批注 */
    OTHER("OTHER", "其他批注");

    private final String code;
    private final String description;

    AnnotationType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static AnnotationType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Annotation type code cannot be null or empty");
        }

        for (AnnotationType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown annotation type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static AnnotationType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Annotation type description cannot be null or empty");
        }

        for (AnnotationType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown annotation type description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}